import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';

import parse from '@dfeidao/atom-web/dt/parse';
import p006 from './p006';
interface Par extends Event {
	page_no: number;
}
export default async function a011(fd: IFeidaoAiBrowserComponent, e: Par) {
	// todo

	//// 分页控件的点击响应事件
	const ch_sj = fd.data.node.querySelector<HTMLDataElement>('[data-id="ch-sj"]').value;
	const ks = parse(ch_sj);
	const js_sj = fd.data.node.querySelector<HTMLDataElement>('[data-id="ch-sj1"]').value;
	const js = parse(js_sj);
	if (ks > js) {
		alert('开始时间大于结束时间');
		return;
	}
	if (ch_sj === '' || js_sj === '') {
		alert('请选择时间段');
		return;
	}
	// 查询会议列表
	const n = fd.data.node.querySelector<HTMLInputElement>('[data-id="conference_theme"]').value;
	const staff_no = get('staff_no');
	const res = await nodejs<Array<{ meeting_no: string }>>('meeting-management/zj-000001/s001', {
		filter: {
			staff_no
		}
	});
	const arr = Array();
	for (let i = 0; i < res.length; i++) {
		arr.push(res[i].meeting_no);
	}
	const dt = await nodejs<{ dt: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }>; c: number }>('meeting-management/zj-000001/s002', {
		filter: {
			meeting_nos: arr,
			pn: 1
		}
	});

	const resdt = await nodejs<{ res: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }> }>('meeting-management/zj-000001/s004', {
		conference_theme: n,
		start_time: ks,
		start_time1: js
	});
	const a = Array();
	for (let i = 0; i < dt.dt.length; i++) {
		for (let j = 0; j < resdt.res.length; j++) {
			if (dt.dt[i].meeting_no === resdt.res[j].meeting_no) {
				const s = dt.dt[i].meeting_no;
				a.push(s);
			}
		}
	}
	const ds = await nodejs<{ dt: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }>; s: Array<{}> }>('meeting-management/zj-000001/s005', {
		filter: {
			meeting_nos: a,
			pn: e.page_no
		}
	});
	// tslint:disable-next-line:no-shadowed-variable
	const d = ds.dt.map((n) => {
		/* 0 不显示时分秒 1 显示秒  2 不显示秒*/
		return ({ ...n, start_time: format(n.start_time, 0) });
	});

	if (ds.s.length > 0) {
		render(fd, d, p001, 'p001', 'inner');
		
	} else {
		render(fd, '', p002, 'p002', 'inner');
	
	}
	
}
